package pr.iceworld.fernando.springbatchquartzlearning.service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import org.springframework.batch.item.ItemWriter;
import org.springframework.stereotype.Component;
import pr.iceworld.fernando.springbatchquartzlearning.entity.Users;
import pr.iceworld.fernando.springbatchquartzlearning.repository.UserMapper;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by ferna on 2018/10/18.
 */
@Component
public class WriterService implements ItemWriter<Users> {
    @Resource
    UserMapper userMapper;
    @Override
    public void write(List<? extends Users> list) throws Exception {
        for (Users user: list) {
            System.out.println("WriterService.write ------>   " + user);
            EntityWrapper<Users> ew = new EntityWrapper<>();
            ew.eq("id", user.getId());
            userMapper.update(user, ew);
        }
    }
}
